/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package configuraciones;

import org.cip.esymons.general.bc.*;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.cip.esymons.general.be.PersonaJuridica;
import org.cip.esymons.general.be.Rubro;

/**
 * @author Lizardo Rios
 */

public class GeneralDelegate {
    public RubroFacadeLocal localRubro;
    public PersonaJuridicaFacadeLocal localEmpresa;

    public GeneralDelegate() {
        localRubro = lookupRubroFacade();
        localEmpresa = lookupPersonaJuridicaFacade();
    }
   
    public void create(Rubro rubro) throws Exception {
        localRubro.create(rubro);
    }

    public void edit(Rubro rubro) throws Exception {
        localRubro.edit(rubro);
    }

    public void remove(Rubro rubro) throws Exception {
        localRubro.remove(rubro);
    }

    public Rubro find(Object id) throws Exception {
        return localRubro.find(id);
    }

    public List<Rubro> findAll() throws Exception {
        return localRubro.findAll();
    }

    private RubroFacadeLocal lookupRubroFacade() {
        try {
            Context c = new InitialContext();
            return (RubroFacadeLocal) c.lookup("java:comp/env/RubroFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    public List<PersonaJuridica> listarEmpresas() throws Exception {
        return localEmpresa.findAll();
    }

    private PersonaJuridicaFacadeLocal lookupPersonaJuridicaFacade() {
        try {
            Context c = new InitialContext();
            return (PersonaJuridicaFacadeLocal) c.lookup("java:comp/env/PersonaJuridicaFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }



    
}
